package cn.sumpu.app.coolsk.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.coolsk.dao.ConfigDao;
import cn.sumpu.app.coolsk.domain.Config;
import cn.sumpu.app.coolsk.exception.AppBusinessException;

/**
 * @author yulong
 *
 */
public class ConfigDaoImpl extends SqlSessionDaoSupport implements ConfigDao {

	private static Logger logger = LoggerFactory.getLogger(ConfigDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<Config> getConfig(Map<String, Object> map)
			throws AppBusinessException {
		try {
			   return getSqlSession().selectList("cn.sumpu.app.coolsk.persistence.ConfigMapper.getConfig",map);
			} catch (Exception e) {
				if (logger.isErrorEnabled()) {
					logger.error("Query database failure.", e);
				}
				throw new AppBusinessException("Query database failure.", e);
			}
	}

	@Override
	public int getConfigCount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			Object obj = (Integer) getSqlSession()
					.selectOne("cn.sumpu.app.coolsk.persistence.ConfigMapper.getConfigCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Query database failure.", e);
			}
			throw new AppBusinessException("Query database failure.", e);
		}
	}

	@Override
	public void updateConfig(Config config) throws AppBusinessException {
		try {
			getSqlSession()
					.update("cn.sumpu.app.coolsk.persistence.ConfigMapper.updateConfig",
							config);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Update database failure.", e);
			}
			throw new AppBusinessException("Update database failure.", e);
		}
	}

	
	

}
